package com.pig4cloud.pigx.robot.ws.collect.ftx;


import com.alibaba.fastjson.JSONObject;
import com.pig4cloud.pigx.robot.ws.collect.bitmex.WsManager;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ParseData {

	public static String source_name = "ftx";
	public static void parse(String msg){
		try{
			JSONObject json = JSONObject.parseObject(msg);
			if(json!= null){
				if(json.get("channel").equals("ticker")){
					//最新成交价格
					String k_mark = "robot_ftx_lastprice_" + json.getString("market").toUpperCase().split("-")[0]+"USDT";

					String v_mark =json.getJSONObject("data").getString("last") + "_" + System.currentTimeMillis();

					WsManager.getInstance().fetchManager.setdata(k_mark,v_mark);
				}
				if(json.get("channel").equals("trades")){
					//标记价格
					String k_mark = "robot_ftx_markprice_" + json.getString("market").toUpperCase().split("-")[0]+"USDT";

					String v_mark =json.getJSONArray("data").getJSONObject(0).getString("price") + "_" + System.currentTimeMillis();

					WsManager.getInstance().fetchManager.setdata(k_mark,v_mark);
				}
			}

		}catch (Exception ex){
			log.error("ftx  parse data error  "+ex.getMessage());
		}
	}

}
